package com.xgpro.pc.talentintroduction.controller;


import com.xgpro.common.controller.BaseController;
import com.xgpro.common.enums.ResultCodeEnum;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.common.utils.FileTool;
import com.xgpro.common.utils.MailTool;
import com.xgpro.common.utils.ReadPropertiesUtil;
import com.xgpro.domain.talentintroduction.entity.IntroduceJob;
import com.xgpro.domain.talentintroduction.entity.Recruitment;
import com.xgpro.domain.talentintroduction.vo.*;
import com.xgpro.mobile.talentintroduction.service.RecruitmentService;
import com.xgpro.pc.talentintroduction.service.RecruitmentPCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author tx
 * @version 1.0
 * @date 2019/8/18 20:15
 */
@CrossOrigin(allowCredentials="true")
@RestController
@RequestMapping("/recruitment_pc")
public class RecruitmentPCController extends BaseController {
    @Autowired
    RecruitmentPCService recruitmentPCService;
    @Autowired
    RecruitmentService recruitmentService;

    /**
     * 按条件查询应聘信息
     * @param frontPC
     * @return
     */
    @RequestMapping("/qryIntroducePc")
    public ResponseResult qryIntroducePc(@RequestBody RecruitmentFrontPC frontPC){
            PCResult pcResult = recruitmentPCService.qryIntroducePc(frontPC);
            return ResponseResult.ok(pcResult);
    }

    /**
     * 应聘信息详情
     * @param id
     * @return
     */
    @RequestMapping("/qryIntroducePcById")
    public ResponseResult qryIntroducePcById(Integer id){
        try{
            return ResponseResult.ok(recruitmentPCService.qryIntroducePcById(id));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 删除应聘信息
     * @param id
     * @return
     */
    @RequestMapping("/deleteByIntroduceId")
    public ResponseResult deleteByIntroduceId(Integer id){
        return ResponseResult.ok(recruitmentPCService.deleteByIntroduceId(id));
    }

    /**
     * 批量删除应聘信息
     * @param ids
     * @return
     */
    @RequestMapping("/deleteIntroduceByList")
    public ResponseResult deleteIntroduceByList(@RequestBody List<Integer> ids){
            return  ResponseResult.ok(recruitmentPCService.deleteIntroduceByList(ids));
    }

    /**
     * 按条件查询招聘信息
     * @param frontPC
     * @return
     */
    @RequestMapping("/qryRecruitmentListPC")
    public ResponseResult qryRecruitmentListPC(@RequestBody RecFront frontPC){
           return ResponseResult.ok(recruitmentPCService.qryRecruitmentListPC(frontPC));
    }

    /**
     * 更新招聘信息
     * @param recruitment
     * @return
     */
    @RequestMapping("/updateRecruitment")
    public ResponseResult updateRecruitment(HttpSession httpSession,@RequestBody Recruitment recruitment){
        try {
            Integer id = (Integer) httpSession.getAttribute("id");
            if (id == null) {
                throw new BusinessRuntimeException(ResultCodeEnum.NO_SESSION.getCode(), ResultCodeEnum.NO_SESSION.getMessage());
            }
            recruitment.setUserId(id);
            return ResponseResult.ok(recruitmentPCService.updateRecruitment(recruitment));
        }catch (BusinessRuntimeException e){
            //e.printStackTrace();
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 添加招聘信息
     * @param httpSession
     * @param recruitment
     * @return
     */
    @RequestMapping("/insertRecruitment")
    public ResponseResult insertRecruitment(HttpSession httpSession,@RequestBody Recruitment recruitment){
        try{
            Integer id=(Integer)httpSession.getAttribute("id");
            if(id==null){
                throw new BusinessRuntimeException(ResultCodeEnum.NO_SESSION.getCode(),ResultCodeEnum.NO_SESSION.getMessage());
            }
            recruitment.setUserId(id);
            return ResponseResult.ok(recruitmentPCService.insertRecruitment(recruitment));
        }catch (BusinessRuntimeException e){
            //e.printStackTrace();
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 招聘信息详情
     * @param id
     * @return
     */
    @RequestMapping("/qryRecruitmentById")
    public ResponseResult qryRecruitmentById(Integer id){
        try {
            return ResponseResult.ok(recruitmentService.qryRecruitmentById(id));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

      /**
     * 删除招聘信息
     * @param id
     * @return
     */
    @RequestMapping("/deleteRecruitmentById")
    public ResponseResult deleteRecruitmentById(Integer id){
        return ResponseResult.ok(recruitmentPCService.deleteRecruitmentById(id));
    }

    /**
     * 批量删除招聘信息
     * @param ids
     * @return
     */
    @RequestMapping("/deleteRecruitementByIds")
    public ResponseResult deleteRecruitementByIds(@RequestBody List<Integer> ids){
            return  ResponseResult.ok(recruitmentPCService.deleteRecruitementByIds(ids));
    }
}
